package SingleThread;

import controller.MonteCarloSimulation;
import GUI.monitor;


public class SingleThread implements Runnable{
	
	public static final int nSimulations = 100000;
	private monitor window;
	
	public SingleThread(monitor window){
		this.window = window;
	}

	@Override
	public void run(){
		
		double TimeStamp = System.currentTimeMillis();
		double Sum = 0;
		
		for (int i=0 ; i< nSimulations ;i++)
		{
			Sum = Sum+ MonteCarloSimulation.singleSimulation((String)window.callPutFlag.getSelectedItem(), Double.valueOf((String)window.s.getSelectedItem()),
					Double.valueOf((String)window.x.getSelectedItem()), Double.valueOf((String)window.t.getSelectedItem()), Double.valueOf((String)window.r.getSelectedItem()), Double.valueOf((String)window.b.getSelectedItem()), Double.valueOf((String)window.v.getSelectedItem()), Integer.valueOf((String)window.nSteps.getSelectedItem()));
			window.pb.setValue(Math.round(i*100/nSimulations));
		}
		
		double sum = MonteCarloSimulation.average(Double.valueOf((String)window.r.getSelectedItem()), Double.valueOf((String)window.t.getSelectedItem()), Sum, nSimulations);
		window.pb.setValue(100);
		double time = System.currentTimeMillis() - TimeStamp;
		window.result.setText("Result : "+sum+". Run time: "+ time + " ms");
	}

}
